#ifndef __FRUSTUM_H
#define __FRUSTUM_H

#include <cmath>
#include "Matrix4.h"
#include <GL/glut.h>

class Frustum {
 public:
	Frustum(double near, double far, double aspect, double FOV) 
		: projectionMatrix(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0) {
		projectionMatrix.m[0][0] = 1.0/(aspect*tan(FOV/2.0));
		projectionMatrix.m[1][1] = 1.0/(tan(FOV/2.0));
		projectionMatrix.m[2][2] = (near+far)/(near-far);
		projectionMatrix.m[2][3] = (2.0*near*far)/(near-far);
		projectionMatrix.m[3][2] = -1.0;
	}

	void loadIntoOpenGL() {
		glMatrixMode(GL_PROJECTION);

		GLdouble *projectionTranspose = new GLdouble[16];

		for (int i=0; i<4; i++) {
			for (int j=0; j<4; j++) {
				projectionTranspose[4*i+j] = projectionMatrix.m[j][i];
			}
		}

		glLoadMatrixd(projectionTranspose);
	}
	
	Matrix4 getMatrix() {
		return projectionMatrix;
	}

	Matrix4 projectionMatrix;
};

#endif
